<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title> {$action} | {:get_opinion('title')}</title>

    <include file="Public:head"/>

</head>
<body class="skin-blue">

{:W('Common/header')}

<div class="wrapper row-offcanvas row-offcanvas-left">
    {:W('Common/sideMenu')}


    <!-- Right side column. Contains the navbar and content of the page -->
    <aside class="right-side">
        <!-- Content Header (Page header) -->


        <section class="content-header">
            <h1>
                {$action}
                <small>{$Think.config.title}</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="{$module_url}"><i class="fa fa-dashboard"></i> {$module}</a></li>
                <li class="active">{$action}</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">

            <div class="row">
                <div class="col-md-10">
                    <div class="box box-warning">
                        <div class="box-header">
                            <h3 class="box-title">{$action}</h3>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body">


                            <form method="POST">
                                <table class="table table-striped table-bordered table-hover tab">
                                    <volist name="nodeList" id="level1">
                                        <tr>
                                            <td style="font-size: 14px;"><label><input name="data[]" level="1"
                                                                                       type="checkbox"
                                                                                       obj="node_{$level1.id}"
                                                                                       value="{$level1.id}:1:0"/> <b>[项目]</b>
                                                {$level1.title}</label></td>
                                        </tr>
                                        <volist name="level1['data']" id="level2">
                                            <tr>
                                                <td style="padding-left: 30px; font-size: 14px;"><label><input
                                                        name="data[]"
                                                        level="2"
                                                        type="checkbox"
                                                        obj="node_{$level1.id}_{$level2.id}"
                                                        value="{$level2.id}:2:{$level2.pid}"/>
                                                    <b>[模块]</b> {$level2.title}</label></td>
                                            </tr>
                                            <tr>
                                                <td style="padding-left: 50px;">
                                                    <volist name="level2['data']" id="level3">
                                                        <label><input name="data[]" level="3" type="checkbox"
                                                                      obj="node_{$level1.id}_{$level2.id}_{$level3.id}"
                                                                      value="{$level3.id}:3:{$level3.pid}"/>
                                                            {$level3.title}</label> &nbsp;&nbsp;&nbsp;
                                                    </volist>
                                                </td>
                                            </tr>
                                        </volist>
                                    </volist>
                                </table>
                                <input type="hidden" name="id" value="{$info.id}"/>

                                <div class="col-md-8" id="success"
                                     style="font-size:16px;color: red;text-align: left; display:none;"></div>

                                <div class="col-md-10 margin">
                                    <div class="form-actions">
                                        <div class="col-md-6 margin">
                                            <button class="btn btn-info submit">提交</button>

                                            <button class="btn zwhite reset" onclick="return false;">重置</button>


                                            <button class="btn white reset" onclick="return false;">重置</button>

                                            <button type="button" class="btn btn-danger empty" id="check_cancel"
                                                    onclick="return false;">清空
                                            </button>
                                        </div>
                                    </div>
                                </div>

                            </form>


                        </div>
                    </div>
                </div>
            </div>


        </section>
        <!-- /.content -->
    </aside>
    <!-- /.right-side -->
</div>
<!-- ./wrapper -->

<include file="Public:foot"/>
<script>
    jQuery(document).ready(function () {
        $('input').iCheck('destroy');

        $("#check_cancel").click(function () {
            $("#cache_table :checkbox").attr("checked", false);
            $("span").removeClass("checked");
        });

        //初始化数据
        function setAccess() {
            //清空所有已选中的
            $("input[type='checkbox']").prop("checked", false);
            //数据格式：
            //节点ID：node_id；1，项目；2，模块；3，操作
            //节点级别：level；
            //父级节点ID：pid
            var access = $.parseJSON('{$info.access}');
            var access_length = access.length;
            if (access_length > 0) {
                for (var i = 0; i < access_length; i++) {
                    $("input[type='checkbox'][value='" + access[i]['val'] + "']").prop("checked", "checked");
                }
            }
        }

        //执行初始化数据操作
        setAccess();
        //为项目时候全选本项目所有操作
        $("input[level='1']").click(function () {
            var obj = $(this).attr("obj") + "_";
            $("input[obj^='" + obj + "']").prop("checked", $(this).prop("checked"));
        });
        //为模块时候全选本模块所有操作
        $("input[level='2']").click(function () {
            var obj = $(this).attr("obj") + "_";
            $("input[obj^='" + obj + "']").prop("checked", $(this).prop("checked"));
            //分隔obj为数组
            var tem = obj.split("_");
            //将当前模块父级选中
            if ($(this).prop('checked')) {
                $("input[obj='node_" + tem[1] + "']").prop("checked", "checked");
            }
        });
        //为操作时只要有勾选就选中所属模块和所属项目
        $("input[level='3']").click(function () {
            var tem = $(this).attr("obj").split("_");
            if ($(this).prop('checked')) {
                //所属项目
                $("input[obj='node_" + tem[1] + "']").prop("checked", "checked");
                //所属模块
                $("input[obj='node_" + tem[1] + "_" + tem[2] + "']").prop("checked", "checked");
            }
        });
        //重置初始状态，勾选错误时恢复
        $(".reset").click(function () {
            setAccess();
        });
        //清空当前已经选中的
        $(".empty").click(function () {
            $("input[type='checkbox']").prop("checked", false);
        });
        $(".submit").click(function () {
            commonAjaxSubmit();
        });
    });
</script>
</body>
</html>